/**
 * @description: 根据组件文档生成组件文档的侧边栏
 **/
import path from 'path'
import glob from 'glob'
import fs from 'fs'
const root = process.cwd()
export default function () {
  const mdFiles = glob.sync(path.resolve(root, './src/components/*/*.md'))
  const sidebarItem = []
  mdFiles.forEach((file) => {
    const dirname = path.dirname(file).split('/').pop()
    fs.copyFile(file, `./docs/components/${dirname}.md`,(err)=>{
      console.log('文档写入:',`${dirname}.md`)
      err&&console.log("Error Found:", err)
    });
    sidebarItem.push({
      text: dirname,
      link: `/components/${dirname}`,
    })
  })
  return sidebarItem
}

